﻿using OpcUaHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace FPSO.HMI.Utils
{
    internal class AuthUtil
    {
        /// <summary>
        /// 鉴权操作
        /// </summary>
        /// <returns>管理员：true，其它：false</returns>
        public static bool IsHasPermission()
        {
			//DEBUG暂时不启用用户权限管理
			//return true;
            try
            {
                if (((App)Application.Current).LoginStatus == 1)
                {
                    return true;
                }
                else
                {
                    MessageBox.Show("当前为普通用户：" + GetLoginUser() + "，无操作权限！", "权限校验失败");
                    return false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("未知错误：" + ex.Message.ToString(), "权限校验失败");
                return false;
            }

        }

        /// <summary>
        /// 设置全局登录状态，0：普通用户，1：管理员用户
        /// </summary>
        /// <param name="type">状态码</param>
        public static void SetLoginStatus(int type)
        {
            ((App)Application.Current).LoginStatus = type;
        }

        /// <summary>
        /// 设置当前登录用户
        /// </summary>
        /// <param name="type">用户名</param>
        public static void SetLoginUser(string username)
        {
            ((App)Application.Current).LoginUser = username;
        }

        /// <summary>
        /// 获取当前登录用户
        /// </summary>
        /// <returns>用户名</returns>
        public static string GetLoginUser()
        {
            return ((App)Application.Current).LoginUser;
        }
    }
}
